package com.example.sneakerappforme1105.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.example.sneakerappforme1105.bean.Goods;
import com.example.sneakerappforme1105.bean.User;

import java.util.List;

@Dao
public interface GoodsDao {

    @Query("SELECT * FROM tb_goods")
     List<Goods> queryAllGoods();   // 查询所有商品

    @Query("SELECT * FROM tb_goods WHERE categoryId= :categoryId")
    List<Goods> queryGoodsByCategoryId(long categoryId);    // 根据商品种类查询商品

    @Query("SELECT * FROM tb_goods WHERE goodsId = :goodsId")
    Goods queryGoodsByGoodsId(long goodsId);


    @Insert(onConflict = OnConflictStrategy.REPLACE) // 记录重复时替换原记录
    long insertOneGoods(Goods goods); // 插入一条用户信息

    @Update(onConflict = OnConflictStrategy.REPLACE)// 出现重复记录时替换原记录
    int updateGoods(Goods goods); // 更新商品信息

    @Query("DELETE FROM tb_goods WHERE 1=1")
    void deleteAllGoods();


}
